home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / drivexx.exe / NTRFACE.TXT < prev    next >
Text File  |  1993-01-22  |  11KB  |  254 lines

  1.  
  2. {$F+,S-,R-,B-,O+}
  3.  
  4. UNIT DRIVExx;
  5.  
  6. {******************************************************************************}
  7.                                    INTERFACE
  8. {******************************************************************************}
  9. USES DOS;
  10.  
  11. type
  12.   SectorArray = array[0..1023] of byte;       {because DOS allows sectors AS BIG
  13.                                                AS 1024 bytes and we don't want
  14.                                                to over-write memory when reading
  15.                                                a sector from a disk}
  16.  
  17.   fakeDPB =                                   {3.10 revised}
  18.   record
  19.     bytespersex     : word;    {BPB & DPB}    {start of standard BPB in boot record}
  20.     sexperclust     : byte;    {BPB & DPB}
  21.     FATstart        : word;    {BPB & DPB}
  22.     numFATS         : byte;    {BPB & DPB}
  23.     RootdirEnts     : word;    {BPB & DPB}
  24.     SexOnSmallDisk  : word;    {ignore this}
  25.     mediabyte       : byte;    {BPB & DPB}
  26.     sexperFAT       : word;    {BPB & DPB}
  27.     SexperTrack     : word;    {BPB ONLY}
  28.     NumHeads        : word;    {BPB ONLY}
  29.     HiddenSex       : longint; {BPB ONLY}
  30.     TotSexonDisk    : longint; {BPB ONLY}     {end of standard BPB - 25 bytes}
  31.  
  32.     RootdirSex      : word;    {calculated}
  33.     ROOTstart       : word;    {DPB}
  34.     FirstDataSec    : word;    {DPB}
  35.     TotClusts       : word;    {calculated}
  36.     TotDataClusts   : word;    {DPB}
  37.     Tracks          : word;    {calculated}
  38.     Cylinders       : word;    {calculated}
  39.     Size            : longint; {calculated}
  40.     accessflag      : byte;    {DPB}
  41.     ddunitnum       : byte;    {DPB}
  42.     DPBDataValid    : boolean; {evaluated}
  43.   end;
  44.  
  45. var
  46.   DOSVER            : real;
  47.   DRDOS,
  48.   DevDrvrChainValid,
  49.   NCacheLoaded,                        {3.00}
  50.   NetwareLoaded,                       {3.00}
  51.   StackerLoaded     : boolean;         {3.00, modified 3.12}
  52.   DriveError        : longint;
  53.   NumLogicaldrives,
  54.   InternalFloppies,
  55.   PhysicalFixed,
  56.   NumBlockDevs,
  57.   MachineID         : byte;
  58.   AllLogicalDrives,
  59.   BootableDrives,
  60.   Floppies,
  61.   Hards             : string[32];      {3.00 - change length to 32 from 26}
  62.   ProcessorType     : integer;
  63.   BiosDateString    : string[8];
  64.  
  65.  
  66. PROCEDURE UpdateDrives;
  67.  { Main procedure in unit.  Updates GLOBAL array DRIVES.  Called in unit
  68.    initialization, but should be called again each time there's a chance
  69.    a user can JOIN or ASSIGN a drive, or if a phantom drive might have been
  70.    accessed while shelled out from the main program that USES this unit }
  71.  
  72. FUNCTION DrivExists(drv:char)          : boolean;
  73.  
  74. FUNCTION DriveisNormal(drv:char)       : boolean;
  75.  
  76. FUNCTION DriveisNONDOS(drv:char)       : boolean;
  77.  
  78. FUNCTION DriveisHard(drv:char)         : boolean;
  79.  
  80. FUNCTION DriveisRAMDisk(drv:char)      : boolean;
  81.  
  82. FUNCTION DriveisOtherfixed(drv:char)   : boolean;
  83.  
  84. FUNCTION DriveisNetwork(drv:char)      : boolean;
  85.  
  86. FUNCTION GetNetwareDriveType(drv:char) : byte;       {!3.21}
  87.  
  88. FUNCTION DriveisSubsted(drv:char)      : boolean;
  89.  
  90. FUNCTION DriveisJoined(drv:char)       : boolean;
  91.  
  92. FUNCTION DriveisAssigned(drv:char)     : boolean;
  93.  
  94. FUNCTION DriveisIFS(drv:char)          : boolean;
  95.  
  96. FUNCTION DriveisAliased(drv:char)      : boolean;
  97.   {true only for Assigned, Joined or Substed drives}
  98.  
  99. FUNCTION DriveisRemovable(drv:char)    : boolean;
  100.  
  101. FUNCTION RemovableDrivetype(drv:char)  : byte;
  102.          { returns:
  103.                 0 : can't be determined, may not be removable
  104.                 1 : 5.25" 360K
  105.                 2 : 5.25" 1.2M
  106.                 3 : 3.5" 720K
  107.                 4 : 3.5" 1.44M
  108.                 5 : 3.5" 2.88M
  109.                 6 : TAPE
  110.                 7 : Bernoulli
  111.                 8 : CDROM
  112.               $FF : invalid drive specified }
  113.  
  114. FUNCTION DriveisPhantom(drv:char)      : boolean;
  115.  
  116. FUNCTION DriveMappedTo(drv:char)       : char;
  117.  
  118. FUNCTION ChangeLineSupported(drv:char) : boolean;
  119.  
  120. FUNCTION DiskWasChanged(drv:char)      : boolean;
  121.          {hits the disk only if there's support for Changeline detection}
  122.  
  123. FUNCTION DiskSyze(drv:char)            : longint;  {3.10 name change}
  124.          { returns:
  125.                 0 : removable drive hasn't been accessed, so no valid DPB
  126.                     data to use, or size is unreliable
  127.              else : disk size IN BYTES; if removable, size of last disk
  128.                     accessed in drive}
  129.  
  130. FUNCTION PhysicalType(drv:char)        : byte;
  131.          { This function returns what DOS thinks is the physical type:
  132.                 0 : 320K/360K
  133.                 1 : 1.2 M
  134.                 2 : 720K
  135.                 3 : 8-inch, single-density
  136.                 4 : 8-inch, double-density
  137.                 5 : hard disk
  138.                 6 : Tape
  139.                 7 : 1.44 M (only for DOS 3.3+)
  140.                 8 : Optical drive? CDROM?
  141.                 9 : 2.88 M (only for DOS 5.0+)
  142.                10 : other?
  143.               $FF : abnormal or invalid drive specified }
  144.  
  145. FUNCTION CurrentDir(drv:char)          : pathstr;
  146.          { returns the currently logged directory for the specified drive
  147.            as a complete path, including driveletter, colon and final
  148.            backslash, all in uppercase letters.  If the drive doesn't
  149.            exist - or it's a NetWare drive - a null string is returned }
  150.  
  151. FUNCTION DefaultDrive                  : char;
  152.          { identifies the current default drive as an uppercase letter }
  153.  
  154. FUNCTION WriteDiskSectors(drv:char; first:longint; num:word; var Buf) : word;   {3.10}
  155.          { returns 0 if successful, otherwise BIOS error code in high byte
  156.            and DOS error code in low byte. Eg, returns 128:2 for floppy
  157.            disk not ready, or 2:12 for unformatted disk in drive }
  158.  
  159. FUNCTION ReadDiskSectors(drv:char; first:longint; num:word; var Buf) : word;    {3.10}
  160.          { returns 0 if successful, otherwise BIOS error code in high byte
  161.            and DOS error code in low byte. Eg, returns 128:2 for floppy
  162.            disk not ready, or 2:12 for unformatted disk in drive }
  163.  
  164. FUNCTION DriveIsReady(drv : char) : boolean;
  165.  
  166. FUNCTION ShowBIOSDriveNum(drv:char) : byte;   {3.10}
  167.          { Does not try to figure out DOS redirection commands like JOIN
  168.            or ASSIGN.  Whatever PHYSICAL disk you would hit with a function
  169.            like ReadDiskSectors(drv, 0, 1, buf) is what this returns.  If DRV
  170.            is not a physical disk (eg, RAMDISK) or if DRV is a phantom, the
  171.            function returns 255.  Based on interception of DOS INT 25h call
  172.            and determination of drivenumber passed to BIOS INT 13h Fnc 02h.
  173.  
  174.            IMPORTANT: DOS INT 25h ignores JOIN, but DOES NOT ignore ASSIGN or
  175.                       SUBST!
  176.  
  177.            EXAMPLES:  SUBST A: C:\
  178.                       Y := ShowBIOSDriveNum('A');
  179.                       Y returns 128, not 0
  180.  
  181.                       ASSIGN A: C:
  182.                       Y := ShowBIOSDriveNum('A');
  183.                       Y returns 128, not 0
  184.  
  185.              BUT...   JOIN A: C:\PUKED
  186.                       Y := ShowBIOSDriveNum('A');
  187.                       Y returns 0! (BIOS drive number for A:)
  188.                       Furthermore, after this JOIN command it is impossible to
  189.                       access drive A: with simple DOS commands, such as DIR and
  190.                       CHKDSK; they all return "Invalid drive specification".
  191.                       Yet INT 25h will still read from a floppy in the drive!
  192.                       Worse yet, traversing drive C: with a search program based
  193.                       on DOS FindFirst and FindNext, for example, will cause
  194.                       drive A: to be accessed when the search tries to read
  195.                       anything in directory C:\PUKED! }
  196.  
  197. FUNCTION GETBOOT(drv:char; var S:SectorArray) : word;      {3.10}
  198.  { reads boot sector and puts it directly into byte array S
  199.  
  200.    THE ONLY CHECKING DONE BY THIS PROCEDURE IS ON PHANTOM DRIVES.  ALL OTHERS
  201.    WILL BE HIT BY INT 25h AND ANY REDIRECTION BY SUBST OR ASSIGN WILL AFFECT
  202.    THE OUTCOME!
  203.  
  204.    returns         0 : no error, S contains